import preprocess from 'svelte-preprocess';
// import tailwindcss from 'tailwindcss';
// import tailwindcssJit from '@tailwindcss/jit'
// import autoprefixer from 'autoprefixer';
import {
	resolve
} from 'path'
let target = process.env.TARGET;
const mode = process.env.NODE_ENV;
const prod = mode === 'production';

if (!target) {
	target = "node"
}

const distDir = `dist/${mode}/${target}`

import nodeAdapter from '@sveltejs/adapter-node';
import staticAdapter from '@sveltejs/adapter-static';


/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://github.com/sveltejs/svelte-preprocess
	// for more information about preprocessors
	preprocess: preprocess(
	// 	{
	// 	postcss: {
	// 		plugins: [
	// 			require('@tailwindcss/jit'),
	// 			autoprefixer,
	// 		],
	// 	},
	// }
	),

	kit: {
		// hydrate the <div id="svelte"> element in src/app.html
		target: '#app',
		vite: {
			resolve: {
				alias: {
					$store: resolve('./src/store'),
					$util: resolve('./src/util'),
				}
			},
			mode,
		}
	}
};

if (target === 'static') {
	config.kit.ssr = false;
	config.kit.adapter = staticAdapter({
		pages: distDir,
		assets: distDir,
		fallback: null,
	})
} else {
	config.kit.adapter = nodeAdapter({
		out: distDir,
		precompress: prod,
	})
}

export default config;